﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Medianamik.Core.CodeGeneration
{
    public class DefaultColumns
    {
        private TableColumn _revision = new TableColumn("Revision", SqlType.Int(), true);
        public TableColumn Revision
        {
            get { return _revision; }
        }

        private TableColumn _nodeId = new TableColumn("NodeId", SqlType.UniqueIdentifier(), false);
        public TableColumn NodeId
        {
            get { return _nodeId; }
        }

        private TableColumn _typeId = new TableColumn("TypeId", SqlType.UniqueIdentifier(), false);
        public TableColumn TypeId
        {
            get { return _typeId; }
        }

        private TableColumn _parentNodeId = new TableColumn("ParentNodeId", SqlType.UniqueIdentifier(), true);
        public TableColumn ParentNodeId
        {
            get { return _parentNodeId; }
        }

        private TableColumn _cultureName = new TableColumn("CultureName", SqlType.Nvarchar(10), false);
        public TableColumn CultureName
        {
            get { return _cultureName; }
        }

        private TableColumn _createdBy = new TableColumn("CreatedBy", SqlType.Nvarchar(100), true);
        public TableColumn CreatedBy
        {
            get { return _createdBy; }
        }

        //private TableColumn _modifiedBy = new TableColumn("ModifiedBy", SqlType.Nvarchar(100), true);
        //public TableColumn ModifiedBy
        //{
        //    get { return _modifiedBy; }
        //}

        private TableColumn _isActive = new TableColumn("IsActive", SqlType.Bit(), false);
        public TableColumn IsActive
        {
            get { return _isActive; }
        }

        private TableColumn _isSubEntity = new TableColumn("IsSubEntity", SqlType.Bit(), false);
        public TableColumn IsSubEntity
        {
            get { return _isSubEntity; }
        }

        private TableColumn _hasModifications = new TableColumn("HasModifications", SqlType.Bit(), false);
        public TableColumn HasModifications
        {
            get { return _hasModifications; }
        }

        private TableColumn _position = new TableColumn("Position", SqlType.SmallInt(), false);
        public TableColumn Position
        {
            get { return _position; }
        }

        private TableColumn _path = new TableColumn("Path", SqlType.Nvarchar(500), false);
        public TableColumn Path
        {
            get { return _path; }
    }

        private TableColumn _depth = new TableColumn("Depth", SqlType.Int(), false);
        public TableColumn Depth
        {
            get { return _depth; }
        }

        private TableColumn _createdOn = new TableColumn("CreatedOn", SqlType.DateTime(), false);
        public TableColumn CreatedOn
        {
            get { return _createdOn; }
        }

        private TableColumn _modifiedOn =  new TableColumn("ModifiedOn",   SqlType.DateTime(),         true);
        public TableColumn ModifiedOn
        {
            get { return _modifiedOn; }
        }

        private TableColumn _generation = new TableColumn("Generation", SqlType.Int(), false);
        public TableColumn Generation
        {
            get
            {
                return _generation;
            }
        }

        private TableColumn _extendedData = new TableColumn("ExtendedData", SqlType.Xml(), false);
        public TableColumn ExtendedData
        {
            get
            {
                return _extendedData;
            }
        }

        private  TableColumn[] _all;
        public TableColumn[] All
        {
            get
            {
                return _all ?? (_all = GetAllColumns());
            }
        }

        private TableColumn[] _genTableColumns;
        public TableColumn[] GenTableColumns
        {
            get
            {
                return _genTableColumns ?? (_genTableColumns = new[]
                    {
                        NodeId,Revision,CultureName,IsActive,IsSubEntity,Generation,HasModifications,
                        CreatedOn,Depth,ParentNodeId,Path, Position, TypeId, ModifiedOn, CreatedBy, ExtendedData
                    });
            }
        }

        private TableColumn[] _keys;
        public TableColumn[] Keys
        {
            get
            {
                return _keys ?? (_keys = GetKeyColumns() );
            }
        }

        private TableColumn[] GetAllColumns() 
        {
            return new TableColumn[]
            {
            TypeId,
            NodeId,
            ParentNodeId,
            Revision,
            CultureName,
            Position,
            Path,
            Depth,
            CreatedOn,
            IsActive,
            IsSubEntity,
            ModifiedOn,
            Generation,
            ExtendedData,
            HasModifications,
            CreatedBy
            };
        }

        private TableColumn[] GetKeyColumns()
        {
            return new TableColumn[]
            {
                NodeId,
                CultureName,
                Revision
            };
        }
    }
}
